package com.service.scheduler.sched;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerKey;

import com.service.cache.CacheManager;
import com.service.other.Logger;
import com.service.scheduler.job.SubSpeedJob;
import com.service.scheduler.server.SchedulerCreator;

public class SubSpeedched {

	private Scheduler subSpeedched;
	
	public void init() {
		try {
			subSpeedched = SchedulerCreator.createScheduler(SubSpeedched.class.getSimpleName(), 1, Trigger.DEFAULT_PRIORITY);
			subSpeed();
			CacheManager.instance().schedMap.put(subSpeedched.getSchedulerName(), subSpeedched);
		} catch (SchedulerException e) {
			Logger.err(e);
		}
	}
	/**
	 * @throws SchedulerException 
	 * 30分钟更新一次副发时长
	 */
	private void subSpeed() throws SchedulerException {
		JobKey jobKey = SchedulerCreator.createJobKey("subSpeedched","com.service.cache");
		TriggerKey triggerKey = SchedulerCreator.createTriggerKey("subSpeedched", "com.service.cache");
		//String expr = SchedulerCreator.createHourExpr(1);
		//测试用:
		String expr = SchedulerCreator.createMinuteExpr(30);
		JobDetail jd = SchedulerCreator.createJob(jobKey, SubSpeedJob.class);
		CronTrigger ct = SchedulerCreator.createCronTrigger(triggerKey, expr);
		subSpeedched.scheduleJob(jd, ct);
	}

}
